/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __IFRUSTRUM_H__
#define __IFRUSTRUM_H__

#pragma once

#include "geom/Vector.h"
#include "model/BoundingSphere.h"
#include "model/AABoundingBox.h"

/**
 * \ingroup CoreEngine
 *
 * The Frustum class.
 * A Frustum is a virtual perspetive box that encloses everything a camera can currently see.<br>
 * An ICamera object is also an Frustum.
 * 
 * \version 1.0
 * first version
 *
 * \date 03-28-2007
 *
 * \author juckel
 *
 * \todo Check if a box is inside the frustum
 * 
 */
class DLL_EXPORT Frustum
{
public:
	Frustum(void);
	virtual ~Frustum(void);

	/// Recalculates the frustum
	void calculateFrustum();

	/// Checks if a point is inside the frustum
	bool pointInFrustum(const math::Vector3 &point);

	/// Checks if a sphere is inside the frustum
	bool sphereInFrustum(const model::BoundingSphere &sphere);

	bool boxInFrustum(const model::AABoundingBox &box);

	float* getFrustum();

	/// Enumeration for a frustum side
	enum FrustumSide {
	  RIGHT=0,		///< The RIGHT side of the frustum
	  LEFT=1,		///< The LEFT	 side of the frustum
	  BOTTOM=2,		///< The BOTTOM side of the frustum
	  TOP=3,		///< The TOP side of the frustum
	  BACK=4,		///< The BACK	side of the frustum
	  FRONT=5		///< The FRONT side of the frustum
	};

	enum PlaneData {
		A=0,   ///< The X value of the plane's normal
		B=1,   ///< The Y value of the plane's normal
		C=2,   ///< The Z value of the plane's normal
		D=3    ///< The distance the plane is from the origin
	};

protected:
	/// Normalize the plane
	void normalizePlane(int side);
	
	float m_fFrustum[6][4];		///< The frustum sides
};

#endif
